package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.TablePostMes;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;


@Mapper
public interface TablePostMesMapper {
    @Delete({
        "delete from table_post_mes",
        "where postmesId = #{postmesid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer postmesid);

    @Insert({
        "insert into table_post_mes (postmesId, fromuserId, ",
        "touserId, content, ",
        "createtime, postId)",
        "values (#{postmesid,jdbcType=INTEGER}, #{fromuserid,jdbcType=INTEGER}, ",
        "#{touserid,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, ",
        "now(), #{postid,jdbcType=INTEGER})"
    })
    int insert(TablePostMes record);

    @Select({
        "select",
        "postmesId, fromuserId, touserId, content, createtime, postId",
        "from table_post_mes",
        "where postmesId = #{postmesid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="postmesId", property="postmesid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="fromuserId", property="fromuserid", jdbcType=JdbcType.INTEGER),
        @Result(column="touserId", property="touserid", jdbcType=JdbcType.INTEGER),
        @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="postId", property="postid", jdbcType=JdbcType.INTEGER)
    })
    TablePostMes selectByPrimaryKey(Integer postmesid);

    @Select({
        "select",
        "postmesId, fromuserId, touserId, content, createtime, postId",
        "from table_post_mes"
    })
    @Results({
        @Result(column="postmesId", property="postmesid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="fromuserId", property="fromuserid", jdbcType=JdbcType.INTEGER),
        @Result(column="touserId", property="touserid", jdbcType=JdbcType.INTEGER),
        @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="postId", property="postid", jdbcType=JdbcType.INTEGER)
    })
    List<TablePostMes> selectAll();

    /*通过userID查询帖子通知信息*/
    @Select("select * from table_post_mes where touserId=#{touserId}")
    List<TablePostMes> selectBytouserId(@Param("touserId")Integer touserId);

    @Update({
        "update table_post_mes",
        "set fromuserId = #{fromuserid,jdbcType=INTEGER},",
          "touserId = #{touserid,jdbcType=INTEGER},",
          "content = #{content,jdbcType=VARCHAR},",
          "postId = #{postid,jdbcType=INTEGER}",
        "where postmesId = #{postmesid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(TablePostMes record);
}